package foo.bar.wiki.web.action.user;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.action.general.LoginActionBean;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.validation.SimpleError;
import org.apache.shiro.subject.Subject;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class LogoutActionBean extends BaseActionBean {


    @DefaultHandler
    public Resolution logout() {
        Subject subject = getCurrentSubject();
        if (subject.isAuthenticated()) {
            subject.logout();
            return new RedirectResolution(LoginActionBean.class, "view");
        }
        else {
            getContext().getValidationErrors().addGlobalError(new SimpleError("Not authenticated, cannot logout"));
            return getContext().getSourcePageResolution();
        }
    }


}
